//
//  SQLiteManger.swift
//  DerenchedQRCode
//
//  Created by 陈友文 on 2022/11/18.
//

import Foundation
import FMDB


// 数据库管理类
class SQLiteManager:NSObject {
    //创建单例
    private static let manager = SQLiteManager()
    
    private let dbName = "qrCode.db"
    
    class func shareManager() -> SQLiteManager {
        return manager
    }
    
//    数据库地址
    lazy var dbURL: URL = {
        let fileURL = try! FileManager.default.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true).appendingPathComponent(dbName)
        print("数据库地址:",fileURL)
        return fileURL
    }()
    
    // FMDatabase对象（用于对数据库进行操作）
    lazy var db: FMDatabase = {
        let db = FMDatabase(url: dbURL)
        return db
    }()
    
    // FMDatabaseQueue对象（用于多线程事务处理）
        lazy var dbQueue: FMDatabaseQueue? = {
            // 根据路径返回数据库
            let databaseQueue = FMDatabaseQueue(url: dbURL)
            return databaseQueue
    }()

}
